#ifndef ARBITER_STORE_H
#define ARBITER_STORE_H

#include "port.h"
#include "channel.h"
#include "node.h"
#include "lane.h"

#include "ip/and_gate.h"

#include "ip/fabrics.h"

typedef struct NodeArbiterStoreParam
{
    int num_of_receivers;
} NodeArbiterStoreParam;

class NodeArbiterStore : public Node
{
public:
    int reg_grant_id;
    List<bool> reg_requests;
    bool reg_request_not_empty;
    int reg_grant_id_org;
    List<bool> reg_mask_f;
    List<bool> reg_mask_t;
    List<bool> reg_mask;
    List<bool> reg_masked_request;
    int reg_grant_id_masked;
    List<ChannelStoreFabricReceiver *> port_receivers;
    List<LaneChannelStoreFabricBusReceiver *> port_receiver_lanes;
    ChannelStoreFabricSender * port_sender;
    LaneChannelStoreFabricBusSender * port_sender_lane;
    List<PortOut<bool> *> port_halt_ins;
    PortOut<bool> * port_halt;
    NodeAndGate * node_halt_detect;

    NodeArbiterStore(Node *parent, NodeArbiterStoreParam params);
    NodeTaskList tasks() const override;

    void task_halt_detection();
    void task_check_and_rotate();
};

#endif // ARBITER_STORE_H